home *** CD-ROM | disk | FTP | other *** search
- Path: news.iag.net!news
- From: jatmon@iag.net (John R Buchan)
- Newsgroups: comp.lang.c
- Subject: Re: Problem with stringcopy
- Date: 7 Jan 1996 00:18:52 GMT
- Organization: Internet Access Group, Orlando, Florida
- Message-ID: <4cn3hc$ps6@news.iag.net>
- References: <4clguu$9fs@eagle.novo.dk> <yewvimppjz5.fsf@hyll.idt.unit.no> <4cmafq$bm5@clarknet.clark.net> <4cmcdu$bm5@clarknet.clark.net>
- NNTP-Posting-Host: pm2-orl2.iag.net
- X-Newsreader: WinVN 0.99.7
-
- In article <4cmcdu$bm5@clarknet.clark.net>, eamick@clark.net says...
- >
- >Eric Amick (eamick@clark.net) wrote:
- >>>char *Stringcopy(char *source, int startpos, size_t length)
- >>>{
- >>> char tmpstring[SIZEBIGENOUGH];
- >>> strncpy((char *)(source+startpos),tmpstring,length);
- >>> return tmpstring;
- >>>}
- >>
- >>This won't work as written; the first two arguments to strncpy() are
- >>reversed. The cast is also unnecessary.
- >
- >Not to mention that returning a pointer to a local array is a bad idea.
- >I *KNEW* there was something I missed... ;-)
-
- char *strncpy( const char *dest, const char *src, int length);
-
- Just a reminder: if strlen(src) >= length, strncpy will not append a '\0'
- to dest. You will have to do it yourself.
-
- --
- John R Buchan -:|:- Looking for that elusive FAQ? ftp to:
- jatmon@mail.iag.net -:|:- rtfm.mit.edu /pub/usenet-by-group/....
-
-